<template>
    <div class="Breadcrumb">
        <el-breadcrumb separator="/" class="biaoqian">
            <el-breadcrumb-item :to="{ path: '/registrarInterface' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>教学基础信息管理</el-breadcrumb-item>
            <el-breadcrumb-item>课程管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>
    </div>
    <div class="showUnTicketInfo">
        <div class="box">
            <el-row :gutter="10" class="mb8" style="margin-left: 20px;">
                <el-col :span="1.5">
                    <el-button type="primary" :icon="Plus" size="mini" @click="handleAdd">添加课程</el-button>
                </el-col>
            </el-row>
        </div>

        <div class="box-content">
            <el-table :data="dataList" height="450" style="width: 100%">
                <el-table-column label="课程名称" prop="name" :show-overflow-tooltip="true" align="center" />
                <el-table-column label="学分" prop="credits" :show-overflow-tooltip="true" align="center" />
                <el-table-column label="课程类别" prop="category" :show-overflow-tooltip="true" align="center" />
                <el-table-column label="开课学期" prop="semester" align="center" />
                <el-table-column label="考核方式" prop="assessmentMethod" align="center" />
                <el-table-column label="上课开始周次" prop="startWeek" align="center" />
                <el-table-column label="上课结束周次" prop="endWeek" align="center" />
                <el-table-column label="上课周次" prop="weeks" align="center" />
                <el-table-column label="总学时" prop="totalHours" align="center" />
                <el-table-column label="选课方式" prop="selectionMethod" align="center" />
                <el-table-column label="操作" width="100px" align="center">
                    <template #default="scope">
                        <el-button @click="handleEdit(scope.row)" :icon="Edit" size="mini"
                            style="width: 5px; height: 1px;  "></el-button>
                        <el-popconfirm title="确定删除吗" confirm-button-text="确定" cancel-button-text="取消" icon="InfoFilled"
                            @confirm="handleDelete(scope.row)" hide-after="0">
                            <template #reference>
                                <el-button :icon="Delete" size="mini" style="width: 1px; height: 1px; "></el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination layout="prev, pager, next" :total=pageTotal :page-size="pageSize"
                    v-model:current-page="curPage" />
            </div>
            <CourseDialog :showDialog="showDialog" @dialogClosed="handleDialogClosed" :dialogType="dialogType"
                :applyId="applyId" :editForm="editForm">
            </CourseDialog>
        </div>
    </div>

</template>

<script>
import api from '@/api/api';
import CourseDialog from '@/components/RegistrarComponents/CourseDialog.vue';
import { Delete, Edit, Search, Share, Upload, Refresh, Plus } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus';

export default {
    components: {
        CourseDialog
    },
    mounted() {
        this.getData()
    },
    data() {
        return {
            dataList: [],
            curPage: 1,
            pageSize: 5,
            pageTotal: 0,
            showDialog: false,
            dialogType: 'add',
            applyId: '',
            editForm: '',
        }
    },
    methods: {
        getData() {
            api.course.page(this.curPage, this.pageSize)
                .then((res) => {
                    this.dataList = res.data.data.records
                    this.pageTotal = res.data.data.total
                })
                .catch((err) => {
                    console.log(err)
                })
        },
        handleAdd() {
            this.dialogType = 'add'
            this.showDialog = true
        },
        handleDialogClosed() {
            this.showDialog = false
            this.getData()
        },
        handleEdit(row) {
            this.editForm = JSON.parse(JSON.stringify(row))
            this.applyId = row.id
            this.dialogType = 'edit'
            this.showDialog = true
        },
        handleDelete(row) {
            api.course.del(row.id).then(() => {
                ElMessage({
                    message: '删除成功',
                    type: 'success'
                })
                this.getData()
            }).catch((err) => {
                console.log(err)
            })
        }
    },
    watch: {
        curPage(newValue, oldValue) {
            this.getData()
        }
    },
    computed: {
        Search() {
            return Search
        },
        Refresh() {
            return Refresh
        },
        Plus() {
            return Plus
        },
        Edit() {
            return Edit
        },
        Delete() {
            return Delete
        }
    }


}
</script>

<style></style>